package com.eightbears.beboy.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eightbears.beboy.R;
import com.eightbears.beboy.base.util.CommonUtils;
import com.eightbears.beboy.entity.HomeListEntity;

/**
 *
 * Created by Bao on 2016/12/7.
 */

public class UserPublishInfoListAdapter extends BaseQuickAdapter<HomeListEntity.Post, BaseViewHolder> {

    public String time = "0";
    private TextView tv_time;
    private ImageView iv_time_point;
    public UserPublishInfoListAdapter() {
        super(R.layout.item_user_publish, null);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, HomeListEntity.Post homeMessageEntity) {
        baseViewHolder.setText(R.id.tv_post, homeMessageEntity.getPost())
                .addOnClickListener(R.id.rl_comment);

        ImageView iv_img = baseViewHolder.getView(R.id.iv_img);
        tv_time = baseViewHolder.getView(R.id.tv_time);
        iv_time_point = baseViewHolder.getView(R.id.iv_time_point);
        iv_img.setImageResource(R.mipmap.default_icon);
        if(homeMessageEntity.isHeadTitle())
            showLeft();
        else
            hindLeft();


        if(homeMessageEntity.getRepost() != null && homeMessageEntity.getRepost().getImages() != null) {
            CommonUtils.loadImageView(mContext,
                    homeMessageEntity.getRepost().getImages().get(0), R.mipmap.default_icon, iv_img);
        } else if(homeMessageEntity.getImages() != null) {
            CommonUtils.loadImageView(mContext,
                    homeMessageEntity.getImages().get(0), R.mipmap.default_icon, iv_img);
        }

        tv_time.setText(CommonUtils.TimeStamp2Date(homeMessageEntity.getCreated_at(), "MM月dd日"));
    }


    private void showLeft(){
        tv_time.setVisibility(View.VISIBLE);
        iv_time_point.setVisibility(View.VISIBLE);
    }

    private void hindLeft(){
        tv_time.setVisibility(View.GONE);
        iv_time_point.setVisibility(View.GONE);
    }
}
